﻿using System;
using System.Collections.Generic;
using System.Text;

namespace _010_011_012操作符详解_9_一元操作符
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int X = 100;
            int y = +X; //100
            Console.WriteLine(y);
            int z = -X;//-100
            Console.WriteLine(z);
            //求相反数
            int q = -(-X);
            Console.WriteLine(q);


            //Console.WriteLine(int.MaxValue);
            //Console.WriteLine(int.MinValue);
            //int w = int.MinValue;
            //try
            //{
            //    int e = checked(-w);
            //    Console.WriteLine(w);
            //    Console.WriteLine(e);
            //}
            //catch (Exception ex)
            //{

            //    Console.WriteLine(ex);//System.OverflowException: 算术运算导致溢出。
            //}

            int r = 12345678;
            int t = ~r;
            Console.WriteLine(t);//-12345679
            string Xstr1 = Convert.ToString(r, 2).PadLeft(32, '0');
            string Xstr2 = Convert.ToString(t, 2).PadLeft(32, '0');
            //55分
            Console.WriteLine(Xstr1);
            Console.WriteLine(Xstr2);


        }
    }
}
 